package demo;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;                  // 持续时间
import javafx.animation.Timeline;			  
import javafx.animation.KeyFrame;             
import javafx.animation.SequentialTransition; 
import javafx.animation.PauseTransition;     // 暂停,在顺序动画中的两个动画之间使用

// 顺序动画(多个动画按顺序播放)
public class SequentialTransitionDemo extends Application { 
	private HBox root = new HBox(50);
	private Circle c1;
	private Circle c2;
	private Timeline t1;
	private Timeline t2;
	private SequentialTransition st;	
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		root.setPadding(new Insets(50));
		
		// 两个圆顺序变色
		c1 = new Circle(60); 
		
		c2 = new Circle(60);
		root.getChildren().addAll(c1, c2);
		
		Scene scene = new Scene(root, 400, 300);
		stage.setScene(scene);
		stage.show();
		
		// 动画
		t1 = new Timeline(new KeyFrame(Duration.millis(1000), e -> changeColor(c1) ));
		t2 = new Timeline(new KeyFrame(Duration.millis(1000), e -> changeColor(c2) ));
		
		// 顺序动画
		st = new SequentialTransition(t1, new PauseTransition(Duration.millis(0)), t2);		// 暂停动画
		st.setCycleCount(Timeline.INDEFINITE);     // 一起设置循环次数
		st.play();
	}
	
	// 随机改变圆的颜色
	public void changeColor(Circle circle) {
		circle.setFill(Color.color(Math.random(), Math.random(), Math.random()));
	}
}



		
			
